//
//  RCSearchAllCityTagDataModel.m
//  RocketProject
//
//  Created by chen jiedan on 13-6-26.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCSearchAllCityTagDataModel.h"
#import "FrameworkRelativeDefines.h"
#import "NSString+NSString_Ex_.h"

@implementation RCTagItem

- (id) initWithDic:(NSDictionary *)dic
{
    self = [super init];
    if (self) {
        self.tagID      = [dic stringValueForKey:@"id" defaultValue:nil operation:NSStringOperationTypeNone];
        self.tagName    = [dic stringValueForKey:@"name" defaultValue:nil operation:NSStringOperationTypeNone];
    }
    return self;
}

- (void) dealloc
{
    self.tagName = nil; self.tagID = nil;
    [super dealloc];
}

@end

@implementation RCSearchAllCityTagDataModel

@synthesize districtTags = _districtTags;
@synthesize categorieTags= _categorieTags;

// 将JSON数据解析为数据模型
-(id) parseDataFromJSON:(NSDictionary*)data
{
    // 输入参数判断
    if ( nil == data )
        return nil;
    
    // 分配数据模型对象内存
    RCSearchAllCityTagDataModel *retObject = nil;
    retObject = [[RCSearchAllCityTagDataModel alloc] init];
    if ( nil == retObject )
        return retObject;
    
    retObject.err = [[[ServerError alloc] initWithDic:data] autorelease];
    
    NSMutableArray *districtlistItems = [[NSMutableArray alloc] init];
    NSMutableArray *categorylistItems = [[NSMutableArray alloc] init];

    NSDictionary *dataDic = [data dictionaryValueForKey:@"data" defaultValue:nil];

    
    
    NSArray *dataItems = [dataDic arrayValueForKey:@"districts" defaultValue:nil];
    for (NSDictionary *dic in dataItems) {
        RCTagItem *tag = [[RCTagItem alloc] initWithDic:dic];
        if (![NSString stringIsNullOrEmpty:tag.tagName]) {
            [districtlistItems addObject:tag];
        }
        [tag release];
    }
    retObject.districtTags = districtlistItems;
    [districtlistItems release];
    
    
    NSArray *categoryItems = [dataDic arrayValueForKey:@"categories" defaultValue:nil];
    for (NSDictionary *dic in categoryItems) {
        RCTagItem *tag = [[RCTagItem alloc] initWithDic:dic];
        if (![NSString stringIsNullOrEmpty:tag.tagName]) {
            [categorylistItems addObject:tag];
        }
        [tag release];
    }
    retObject.categorieTags = categorylistItems;
    [categorylistItems release];
    
    // 返回结果数据模型
    return [retObject autorelease];
}


@end


@implementation RCSearchCityIDDataModel
@synthesize cityID = _cityID;

- (void) dealloc
{
    self.cityID = nil;
    [super dealloc];
}
// 将JSON数据解析为数据模型
+(id) parseDataFromJSON:(NSDictionary*)data
{
    // 输入参数判断
    if ( nil == data )
        return nil;
    
    // 分配数据模型对象内存
    RCSearchCityIDDataModel *retObject = nil;
    retObject = [[RCSearchCityIDDataModel alloc] init];
    if ( nil == retObject )
        return retObject;
    
    retObject.err = [[[ServerError alloc] initWithDic:data] autorelease];
    NSDictionary *dic = [data dictionaryValueForKey:@"data" defaultValue:nil];
    retObject.cityID = [dic stringValueForKey:@"cityid" defaultValue:nil operation:NSStringOperationTypeNone];
    
    
    // 返回结果数据模型
    return [retObject autorelease];
}

@end
